package com.engine.hitech.duss.budget.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.hitech.duss.budget.utils.BgUtil;
import com.engine.hitech.duss.budget.utils.DBUtil;
import com.wbi.util.StringUtil;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2021-03-10
 * @Description: ${description}
 * @ModifyLog:
 **/

public class WeaBudgetWeb {
    /**
     * @Description: 获取汇总表任务数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getSumTaskData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSumTaskData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        BaseBean baseBean = new BaseBean();
        JSONArray dataList = new JSONArray();
        //预算组织
        String orders_param = Util.null2String( request.getParameter( "orders" ) );
        //版本号
        String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
        baseBean.writeLog( ">>>>>getSumTaskData>>>orders_param=" + orders_param );
        try {
            Map<String, Object> dataMap = BgUtil.getSumStataus(bbh_param, orders_param );
            String status = "未编制";
            String taskid = (String) dataMap.get( "taskids" );
            int counts = (int) dataMap.get( "counts" );
            int wbzcount = (int) dataMap.get( "wbzcount" );
            int bzzcount = (int) dataMap.get( "bzzcount" );
            int yshcount = (int) dataMap.get( "yshcount" );
            if(counts>0){
                if(yshcount==counts){
                    status = "已审核";
                }
                if( (wbzcount==0 && bzzcount>0) && bzzcount<=counts){
                    status = "编制中";
                }
            }
            JSONObject jsonData = new JSONObject();
            jsonData.put( "xh", "1" );
            jsonData.put( "bdbh", "001" );
            jsonData.put( "bdmc", "科目汇总表" );
            jsonData.put( "bzzt", status );
            jsonData.put( "count", (wbzcount+bzzcount));
            jsonData.put( "taskid", taskid );
            dataList.add( jsonData );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList.toJSONString();
    }

    /**
     * @Description: 获取基准表任务数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getBaseTaskData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getBaseTaskData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        BaseBean baseBean = new BaseBean();
        //部门编码
        String orders_param = Util.null2String( request.getParameter( "orders" ) );
        //版本号
        String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
        //科目编码
        String kmbm_param = Util.null2String( request.getParameter( "kmbm" ) );
        //表单名称
        String bdmc_param = Util.null2String( request.getParameter( "bdmc" ) );
        //编制状态
        String bzzt_param = Util.null2String( request.getParameter( "bzzt" ) );
        baseBean.writeLog( ">>>>>getBaseTaskData>>>orders_param=" + orders_param );
        JSONArray dataList = new JSONArray();
        try {
            RecordSet rs = new RecordSet();
            String sql = "  select id,name,appid,kmbm,kmmc,bdmc,zhbzsj,bzzt from view_custom_task " +
                    "where groupid='3' and bbh='" + bbh_param + "'";
            if (StringUtil.isNotBlank( orders_param )) {
                sql += BgUtil.converOrders(orders_param);
            }
            if (StringUtil.isNotBlank( kmbm_param )) {
                sql += " and kmbm='" + kmbm_param + "'";
            }
            if (StringUtil.isNotBlank( bdmc_param )) {
                sql += " and bdmc='" + bdmc_param + "'";
            }
            if (StringUtil.isNotBlank( bzzt_param )) {
                sql += " and bzzt='" + bzzt_param + "'";
            }
            baseBean.writeLog( ">>>>sql=" + sql );
            rs.executeQuery( sql );
            while (rs.next()) {
                JSONObject jsonData = new JSONObject();
                jsonData.put( "id", Util.null2String( rs.getString( "id" ) ) );
                jsonData.put( "name", Util.null2String( rs.getString( "name" ) ) );
                jsonData.put( "appid", Util.null2String( rs.getString( "appid" ) ) );
                jsonData.put( "kmbm", Util.null2String( rs.getString( "kmbm" ) ) );
                jsonData.put( "kmmc", Util.null2String( rs.getString( "kmmc" ) ) );
                jsonData.put( "bdmc", Util.null2String( rs.getString( "bdmc" ) ) );
                jsonData.put( "zhbzsj", Util.null2String( rs.getString( "zhbzsj" ) ) );
                jsonData.put( "bzzt", Util.null2String( rs.getString( "bzzt" ) ) );
                dataList.add( jsonData );
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList.toJSONString();
    }
    /**
     * @Description: 获取套表任务数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getSetTaskData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSetTaskData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        BaseBean baseBean = new BaseBean();
        //部门编码
        String orders_param = Util.null2String( request.getParameter( "orders" ) );
        //版本号
        String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
        //科目编码
        String bdbh_param = Util.null2String( request.getParameter( "bdbh" ) );
        //表单名称
        String bdmc_param = Util.null2String( request.getParameter( "bdmc" ) );
        //编制状态
        String bzzt_param = Util.null2String( request.getParameter( "bzzt" ) );
        baseBean.writeLog( ">>>>>getSetTaskData>>>orders_param=" + orders_param );
        JSONArray dataList = new JSONArray();
        try {
            RecordSet rs = new RecordSet();
            String sql = "  select id,name,appid,bdbh,bdmc,zhbzsj,bzzt from view_custom_task " +
                    "where groupid='5' and bbh='" + bbh_param + "'";
            if (StringUtil.isNotBlank( orders_param )) {
                sql += BgUtil.converOrders(orders_param);
            }
            if (StringUtil.isNotBlank( bdbh_param )) {
                sql += " and bdbh='" + bdbh_param + "'";
            }
            if (StringUtil.isNotBlank( bdmc_param )) {
                sql += " and bdmc='" + bdmc_param + "'";
            }
            if (StringUtil.isNotBlank( bzzt_param )) {
                sql += " and bzzt='" + bzzt_param + "'";
            }
            rs.executeQuery( sql );
            while (rs.next()) {
                JSONObject jsonData = new JSONObject();
                jsonData.put( "id", Util.null2String( rs.getString( "id" ) ) );
                jsonData.put( "name", Util.null2String( rs.getString( "name" ) ) );
                jsonData.put( "appid", Util.null2String( rs.getString( "appid" ) ) );
                jsonData.put( "bdbh", Util.null2String( rs.getString( "bdbh" ) ) );
                jsonData.put( "bdmc", Util.null2String( rs.getString( "bdmc" ) ) );
                jsonData.put( "zhbzsj", Util.null2String( rs.getString( "zhbzsj" ) ) );
                jsonData.put( "bzzt", Util.null2String( rs.getString( "bzzt" ) ) );
                dataList.add( jsonData );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList.toJSONString();
    }

    /**
     * @Description: 获取明细表任务数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getDetailTaskData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getDetailTaskData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        BaseBean baseBean = new BaseBean();
        //部门编码
        String orders_param = Util.null2String( request.getParameter( "orders" ) );
        //版本号
        String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
        //科目编码
        String kmbm_param = Util.null2String( request.getParameter( "kmbm" ) );
        //表单名称
        String bdmc_param = Util.null2String( request.getParameter( "bdmc" ) );
        //编制状态
        String bzzt_param = Util.null2String( request.getParameter( "bzzt" ) );
        baseBean.writeLog( ">>>>>getDetailTaskData>>>orders_param=" + orders_param );
        JSONArray dataList = new JSONArray();
        try {
            RecordSet rs = new RecordSet();
            String sql = "  select id,name,appid,kmbm,kmmc,bdmc,bbh,zhbzsj,bzzt from view_custom_task " +
                    "where groupid in (4,6) and bbh='" + bbh_param + "'";
            if (StringUtil.isNotBlank( orders_param )) {
                sql += BgUtil.converOrders(orders_param);
            }
            if (StringUtil.isNotBlank( kmbm_param )) {
                sql += " and kmbm='" + kmbm_param + "'";
            }
            if (StringUtil.isNotBlank( bdmc_param )) {
                sql += " and bdmc='" + bdmc_param + "'";
            }
            if (StringUtil.isNotBlank( bzzt_param )) {
                sql += " and bzzt='" + bzzt_param + "'";
            }
            rs.executeQuery( sql );
            while (rs.next()) {
                JSONObject jsonData = new JSONObject();
                jsonData.put( "id", Util.null2String( rs.getString( "id" ) ) );
                jsonData.put( "name", Util.null2String( rs.getString( "name" ) ) );
                jsonData.put( "appid", Util.null2String( rs.getString( "appid" ) ) );
                jsonData.put( "kmbm", Util.null2String( rs.getString( "kmbm" ) ) );
                jsonData.put( "kmmc", Util.null2String( rs.getString( "kmmc" ) ) );
                jsonData.put( "bdmc", Util.null2String( rs.getString( "bdmc" ) ) );
                jsonData.put( "zhbzsj", Util.null2String( rs.getString( "zhbzsj" ) ) );
                jsonData.put( "bzzt", Util.null2String( rs.getString( "bzzt" ) ) );
                dataList.add( jsonData );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList.toJSONString();
    }

    /**
     * @Description: 获取编制方案数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getSchemaData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSchemaData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        JSONArray dataList = new JSONArray();
        try {
            RecordSet rs = new RecordSet();
            //版本号
            String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
            String sql = "select id,bbh,famc,bznf,bzksyf,sfndcsbz,zdyybb from uf_bzfa where bbh=?";
            rs.executeQuery( sql, bbh_param );
            while (rs.next()) {
                JSONObject jsonData = new JSONObject();
                jsonData.put( "id", Util.null2String( rs.getString( "id" ) ) );
                jsonData.put( "bbh", Util.null2String( rs.getString( "bbh" ) ) );
                jsonData.put( "famc", Util.null2String( rs.getString( "famc" ) ) );
                jsonData.put( "bznf", Util.null2String( rs.getString( "bznf" ) ) );
                jsonData.put( "bzksyf", Util.null2String( rs.getString( "bzksyf" ) ) );
                String sfndcsbz = Util.null2String( rs.getString( "sfndcsbz" ) );
                sfndcsbz = "0".equals( sfndcsbz ) ? "是" : "否";
                jsonData.put( "sfndcsbz", sfndcsbz );
                String zdyybb = Util.null2String( rs.getString( "zdyybb" ) );
                jsonData.put( "zdyybb", BgUtil.getId2Zdyybb( zdyybb ) );
                dataList.add( jsonData );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataList.toJSONString();
    }

    /**
     * @Description: 引用历史版本
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/refHisVersion")
    @Produces({MediaType.TEXT_PLAIN})
    public String refHisVersion(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<>();
        BaseBean baseBean = new BaseBean();
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        //版本号
        String jsonArr = Util.null2String( request.getParameter( "jsonArr" ) );
        baseBean.writeLog( "jsonArr=" + jsonArr );
        try {
            int successCount = 0;
            JSONArray jsonArray = JSONArray.parseArray( jsonArr );
            for (int i = 0; i < jsonArray.size(); i++) {
                ////任务ID
                String taskid = jsonArray.getJSONObject( i ).getString( "id" );
                //应用ID
                String appid = jsonArray.getJSONObject( i ).getString( "appid" );
                //版本号
                String bbh = jsonArray.getJSONObject( i ).getString( "bbh" );
                baseBean.writeLog( "taskid=" + taskid + ",appid=" + appid + ",bbh=" + bbh );
                String formids = BgUtil.getFormid( appid );
                baseBean.writeLog( "formids=" + formids );
                //老版本的任务ID
                String lastTaskid = BgUtil.getTaskIdBybbh( appid, bbh );
                if (!"".equals( lastTaskid ) && !"".equals( formids )) {
                    baseBean.writeLog( "lastTaskid=" + lastTaskid );
                    String pageDataId = DBUtil.Insert_edc_pagedata();
                    baseBean.writeLog( "pageDataId=" + pageDataId );
                    String[] strs = formids.split( "," );
                    for (int j = 0; j < strs.length; j++) {
                        String formid = strs[j];
                        String mainTable = BgUtil.getMainTable( formid );
                        baseBean.writeLog( "mainTable=" + mainTable );
                        rs.executeQuery( "select * from " + mainTable + " where taskid=?", lastTaskid );
                        rs.next();
                        String lastMainid = Util.null2String( rs.getString( "id" ) );
                        Map<String, String> mainMap = new HashMap<>();
                        rs1.executeQuery( "select fieldname from workflow_billfield where billid=? and viewtype=0", formid );
                        while (rs1.next()) {
                            String fieldname = Util.null2String( rs1.getString( "fieldname" ) );
                            String fieldvalue = Util.null2String( rs.getString( fieldname ) );
                            if (!"".equals( fieldvalue )) {
                                mainMap.put( fieldname, fieldvalue );
                            }
                        }
                        mainMap.put( "taskid", taskid );
                        baseBean.writeLog( "mainMap=" + mainMap.toString() );
                        rs.executeUpdate( "delete from " + mainTable + " where taskid=" + taskid );
                        //插入主表
                        String mainid = DBUtil.InsertMainTable( mainTable, mainMap );
                        //修改节点表
                        DBUtil.Update_edc_tasknode( taskid, pageDataId );
                        //插入数据明细表
                        DBUtil.Insert_edc_pagedatas( appid, mainid, formid, pageDataId );

                        //插入明细数据
                        baseBean.writeLog( "mainid=" + mainid );
                        if (!"".equals( lastMainid ) && !"".equals( mainid )) {
                            List<Map<String, String>> detailtables = BgUtil.getDetailTable( formid );
                            for (Map<String, String> detailtable : detailtables) {
                                String tablename = detailtable.get( "tablename" );
                                rs.executeQuery( "select * from " + tablename + " where mainid=?", lastMainid );
                                while (rs.next()) {
                                    Map<String, Object> dataMap = new HashMap<>();
                                    rs1.executeQuery( "select fieldname from workflow_billfield where billid=? and viewtype=1 and detailtable=?", formid, tablename );
                                    while (rs1.next()) {
                                        String fieldname = Util.null2String( rs1.getString( "fieldname" ) );
                                        String fieldvalue = Util.null2String( rs.getString( fieldname ) );
                                        if (!"".equals( fieldvalue )) {
                                            dataMap.put( fieldname, fieldvalue );
                                        }
                                    }
                                    dataMap.put( "mainid", mainid );
                                    baseBean.writeLog( "dataMap=" + dataMap.toString() );
                                    rs.executeUpdate( "delete from " + tablename + " where mainid=" + mainid );
                                    DBUtil.insertData( tablename, dataMap );
                                }

                            }
                            successCount++;
                        }
                    }
                }
            }
            apidatas.put( "counts", jsonArray.size() );
            apidatas.put( "successCount", successCount );
            apidatas.put( "failureCount", jsonArray.size() - successCount );
        } catch (Exception e) {
            apidatas.put( "api_status", "false" );
            e.printStackTrace();
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取最新版本号
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getNewVersion")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNewVersion(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        String taskbbh = BgUtil.getTaskZxbbh();
        Map<String, String> apidatas = BgUtil.getZxBbhAndId( taskbbh );
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取上一个版本号
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getLastVersion")
    @Produces({MediaType.TEXT_PLAIN})
    public String getLastVersion(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, String> apidatas = new HashMap<>();
        //版本号
        String bbh_param = Util.null2String( request.getParameter( "bbh" ) );
        String sygbbh = BgUtil.getSygbbh( bbh_param );
        apidatas.put( "lastVersion", sygbbh );
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 获取节点和用户信息
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getNodeAndUser")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNodeAndUser(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, String> apidatas = new HashMap<>();
        //版本号
        String taskid = Util.null2String( request.getParameter( "taskid" ) );
        User user = HrmUserVarify.getUser( request, response );
        String userid = user.getUID() + "";
        try {
            ResourceComInfo rci = new ResourceComInfo();
            String nodeid = BgUtil.getNodeid( taskid );
            String name = rci.getLastname( userid );
            apidatas.put( "nodeid", nodeid );
            apidatas.put( "name", name );
            apidatas.put( "userid", userid );
            apidatas.put( "datetime", DateUtil.getDateTime() );
            apidatas.put( "time", DateUtil.getCurrentHourMin() );
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONObject.toJSONString( apidatas );
    }

    /**
     * @Description: 提交填报数据
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/getTaskData")
    @Produces({MediaType.TEXT_PLAIN})
    public String getTaskData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        Map<String, Object> apidatas = new HashMap<>();
        try {
            BaseBean baseBean = new BaseBean();
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            //任务ID
            String taskid = Util.null2String( request.getParameter( "taskid" ) );
            //应用ID
            String appid = Util.null2String( request.getParameter( "appid" ) );
            baseBean.writeLog( ">>>>>>submitTask>>>>taskid=" + taskid + ",appid=" + appid );
            String formids = BgUtil.getFormid( appid );
            baseBean.writeLog( ">>>>>>submitTask>>>>formids=" + formids );
            String[] strs = formids.split( "," );
            for (String formid : strs) {
                String maintable = BgUtil.getMainTable( formid );
                baseBean.writeLog( ">>>>>>submitTask>>>>maintable=" + maintable );
                String sheetname = BgUtil.getSheetName( formid );
                baseBean.writeLog( ">>>>>>submitTask>>>>sheetname=" + sheetname );
                JSONObject sheetdata = new JSONObject();
                rs.executeQuery( "select * from " + maintable + " where taskid=?", taskid );
                rs.next();
                String mainid = Util.null2String( rs.getString( "id" ) );
                baseBean.writeLog( ">>>>>>submitTask>>>>mainid=" + mainid );
                rs1.executeQuery( "select type,fieldname from workflow_billfield where billid=? and viewtype=0", formid );
                while (rs1.next()) {
                    String type = Util.null2String( rs1.getString( "type" ) );
                    String fieldname = Util.null2String( rs1.getString( "fieldname" ) );
                    String fieldvalue = Util.null2String( rs.getString( fieldname ) );
                    if ("161".equals( type )) {
                        JSONArray jsonArray = new JSONArray();
                        if (!"".equals( fieldvalue )) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put( "id", fieldvalue );
                            jsonObject.put( "name", "" );
                            jsonArray.add( jsonObject );
                        }
                        sheetdata.put( fieldname, jsonArray );
                    } else {
                        sheetdata.put( fieldname, fieldvalue );
                    }
                }

                baseBean.writeLog( ">>>>>>submitTask>>>>sheetdata1=" + sheetdata.toJSONString() );
                List<Map<String, String>> detailtables = BgUtil.getDetailTable( formid );
                for (Map<String, String> detailtable : detailtables) {
                    String orderid = detailtable.get( "orderid" );
                    String tablename = detailtable.get( "tablename" );
                    JSONArray detailList = new JSONArray();
                    rs.executeQuery( "select * from " + tablename + " where mainid=?", mainid );
                    int counts = rs.getCounts();
                    if (counts > 0) {
                        int count = 1;
                        while (rs.next()) {
                            JSONObject detaildata = new JSONObject();
                            rs1.executeQuery( "select type,fieldname from workflow_billfield where billid=? and viewtype=1 and detailtable=?", formid, tablename );
                            while (rs1.next()) {
                                String type = Util.null2String( rs1.getString( "type" ) );
                                String fieldname = Util.null2String( rs1.getString( "fieldname" ) );
                                String fieldvalue = Util.null2String( rs.getString( fieldname ) );
                                if ("161".equals( type )) {
                                    JSONArray jsonArray = new JSONArray();
                                    if (!"".equals( fieldvalue )) {
                                        JSONObject jsonObject = new JSONObject();
                                        jsonObject.put( "id", fieldvalue );
                                        jsonObject.put( "name", "" );
                                        jsonArray.add( jsonObject );
                                    }
                                    detaildata.put( fieldname, jsonArray );
                                } else {
                                    detaildata.put( fieldname, fieldvalue );
                                }
                            }
                            baseBean.writeLog( ">>>>>>submitTask>>>>detaildata=" + detaildata.toJSONString() );
                            detaildata.put( "detail_index", count );
                            count++;
                            detailList.add( detaildata );
                        }
                    } else {
                        JSONObject detaildata = new JSONObject();
                        detaildata.put( "detail_index", "1" );
                    }
                    sheetdata.put( "detail_" + orderid, detailList );
                    baseBean.writeLog( ">>>>>>submitTask>>>>sheetdata2=" + sheetdata.toJSONString() );
                }
                apidatas.put( sheetname, sheetdata );
                baseBean.writeLog( ">>>>>>submitTask>>>>datas=" + apidatas.toString() );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONObject.toJSONString( apidatas );
    }


    /**
     * @Description: 创建流程
     * @Param: [request, response]
     * @return: java.lang.String
     * @Author: Dusongsong
     * @Date: 2022/8/10
     */
    @GET
    @Path("/createWorkflow")
    @Produces({MediaType.TEXT_PLAIN})
    public String createWorkflow(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);
        int userid = user.getUID();
        Map<String, Object> apidatas = new HashMap<>();
        try {
            BaseBean baseBean = new BaseBean();
            //workflowid
            String workflowid = Util.null2String( request.getParameter( "workflowid" ) );
            //部门
            String bmbm = Util.null2String( request.getParameter( "bmbm" ) );
            //科室
            String ksbm = Util.null2String( request.getParameter( "ksbm" ) );
            //任务ID
            String taskids = Util.null2String( request.getParameter( "taskids" ) );
            baseBean.writeLog( "workflowid="+workflowid+",bmbm=" + bmbm + ",ksbm="+ksbm+",taskids=" + taskids );
            if("".equals(ksbm)){
                apidatas = BgUtil.createBmkmhzWorkflow(workflowid,ksbm,taskids,userid);
            }else{
                apidatas = BgUtil.createKskmhzWorkflow(workflowid,bmbm,ksbm,taskids,userid);
            }

            baseBean.writeLog( ">>>>>>createWorkflow>>>>apidatas=" + apidatas.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JSONObject.toJSONString( apidatas );
    }
}
